//
//  BAElementView.swift
//  BadAir
//
//  Created by D on 2018/3/25.
//  Copyright © 2018年 D. All rights reserved.
//

import UIKit

enum elementType {
    case PM25
    case PM10
    case NO2
    case SO2
    case O3
    case CO
}

class BAElementView: UIView {
    var moveValue = 0
    private let titleLabel = UILabel()
    private let valueLable = UILabel()
    private let circelDraw = BACircelDraw()
    
    var value: String? {
        didSet {
            if (value == "_") {
                value = "-"
            }
            updateData()
        }
    }
    
    var titleType: elementType? {
        
        didSet {
            var titleText = ""
            switch titleType {
            case .PM25?:
                titleText = "PM2.5"
            case .PM10?:
                titleText = "PM10"
            case .NO2?:
                titleText = "NO2"
            case .SO2?:
                titleText = "SO2"
            case .O3?:
                titleText = "O3"
            case .CO?:
                titleText = "CO"
                
            case .none:
                titleText = ""
            }
            
            titleLabel.text = titleText
            setNeedsLayout()
        }
        
    }
    private func updateData() {
        valueLable.text = value
        circelDraw.value = value
        
        setNeedsLayout()
    
    }
    
    private func setupUI() {
        titleLabel.setupLabel(ofSize: 13, weight: .light, txtColor: UIColor("#12213D"))
        addSubview(titleLabel)
        valueLable.setupLabel(ofSize: 23, weight: .regular, txtColor: UIColor("#12213D"))
        valueLable.alpha = 0
        addSubview(valueLable)
        circelDraw.backgroundColor = UIColor.clear
        addSubview(circelDraw)
        circelDraw.snp.makeConstraints { (make) in
            make.centerY.equalTo(valueLable)
            make.left.equalTo(0)
            make.width.height.equalTo(12)
        }
        valueLable.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.left.equalTo(17)
//            make.right.greaterThanOrEqualToSuperview()
//            make.right.equalToSuperview()
        }
        
        
        titleLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(valueLable)
            
            make.left.equalTo(17)
//            make.right.greaterThanOrEqualToSuperview()
//            make.right.equalToSuperview()
//            make.bottom.equalToSuperview()
        }
        
        self.snp.makeConstraints { (make) in
            make.right.equalTo(titleLabel.snp.right)
            make.bottom.equalTo(titleLabel.snp.bottom)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
